﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace LogFileConnector
{
    class LogValidator
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public bool isValid(string file)
        {
            StreamReader reader = new StreamReader(file);
            try
            {
                ErrorHandler.processInfoOutput("Processing file ... "+file);
                String firstLine = reader.ReadLine();
                reader.Close();

                if (firstLine.IndexOf(Configuration.validLogStartsWith) > -1)
                {
                    ErrorHandler.processInfoOutput("    file ... " + file + "is valid!");
                    return true;
                }
                ErrorHandler.writeLogError(file);
                return false;
            }
            catch (Exception OpenError)
            {
                throw new Exception("Beim Öffnen der Datei " + file + " ist ein Fehler Aufgetreten. Details: " + OpenError.Message);
            }
            finally
            {
                reader.Close();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public List<string> getFileContent(string file) 
        {
            List<string> content = new List<string>();
            StreamReader reader = new StreamReader(file);
            try
            {
                while (!reader.EndOfStream)
                {
                    content.Add(reader.ReadLine());
                }
                reader.Close();
            }
            catch (Exception OpenError)
            {
                throw new Exception("Beim Öffnen der Datei " + file + " ist ein Fehler Aufgetreten. Details: " + OpenError.Message);
            }
            finally
            {
                reader.Close();
            }
            return content;
        }
    }
}
